<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<h1>
${hotel.name}
</h1>
<c:url var="followUrl" value="/hotels/follow"/>
<c:url var="unfollowUrl" value="/hotels/unfollow"/>
<c:url var="loginUrl" value="/login_goto"/>
<br/>
<a id="followstatus" href='javascript:login()'>follow</a>
<br/>
<address>
	${hotel.address}
	<br />
	${hotel.city}, ${hotel.state}, ${hotel.zip}
	<br />
	${hotel.country}
	<br />
	fans:${hotel.followCount}
	<br />
	View:${viewCount}
</address>


<script type="text/javascript">	

	$(document).ready(function() {
		<security:authorize ifAllGranted="ROLE_USER">
		<c:choose>
		   <c:when test="${empty userFollowHotel}">
			$("#followstatus").text("follow");
			$("#followstatus").attr("href","javascript:follow()");
		   </c:when>
		   <c:otherwise>
			$("#followstatus").text("un follow");
			$("#followstatus").attr("href","javascript:unfollow()");
		   </c:otherwise>
		</c:choose>
		</security:authorize>
	});

	function follow() {
		$.post('${followUrl}/${hotel.id}',null,function(data) {
			if (data=='success') {
				$("#followstatus").text("un follow");
				$("#followstatus").attr("href","javascript:unfollow()");
			}
		});
	}

	function unfollow() {
		$.post('${unfollowUrl}/${hotel.id}',null,function(data) {
			if (data=='success') {
				$("#followstatus").text("follow");
				$("#followstatus").attr("href","javascript:follow()");
			}
		});
	}

	function login() {
		window.location.href="${loginUrl}?page="+window.location.toString();
	}
</script>